package cn.ljy.uem.service.impl;

import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.common.exception.model.MyWebException;
import cn.ljy.uem.dao.SchoolTermMapper;
import cn.ljy.uem.model.SchoolTerm;
import cn.ljy.uem.model.query.SchoolTermQuery;
import cn.ljy.uem.service.SchoolTermService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 学期模块的业务层接口
 *
 * @author 凡渊
 * @date 2022/07/18 10:41:40
 */
@Service
@Slf4j
public class ISchoolTermService extends IBaseService<SchoolTerm, SchoolTermQuery> implements SchoolTermService {
    @Autowired
    private SchoolTermMapper mapper;
    @Override
    protected void beforeGet(Serializable id) {

    }

    @Override
    protected void beforeUpdate(SchoolTerm schoolTerm) {

    }

    @Override
    protected void beforeSave(SchoolTerm schoolTerm) {
        if(schoolTerm!=null){
            //判断名字是否重复
            if (mapper.isExistByName(schoolTerm.getName())>0){
                throw new MyWebException("添加失败：该学期已经存在");
            }
            if(schoolTerm.getName()==null){
                throw new MyWebException("添加失败：名字为空");
                //判断开始时间
            } else if (schoolTerm.getBeginDate()==null) {
                throw new MyWebException("添加失败：开始时间为空");
                //判断结束时间
            } else if (schoolTerm.getBeginDate()==null) {
                throw new MyWebException("添加失败：结束时间为空");
                //判断状态
            }
            if (schoolTerm.getClose()==null) {
                schoolTerm.setClose(false);//设置学期状态默认开启
//                throw new MyWebException("添加失败：学期状态为空");
            }
        }else {
            throw new MyWebException("添加失败：添加对象为空");
        }
    }

    @Override
    protected void beforeDelete(Serializable[] ids) {

    }

}
